package io.github.jast90.internship.controller;

import io.github.jast90.common.form.CommonPageRequestBody;
import io.github.jast90.internship.entity.MyClass;
import io.github.jast90.internship.service.MyClassService;
import io.github.jast90.mybatis.pagination.domain.Page;
import io.github.jast90.mybatis.pagination.domain.PageRequest;
import io.github.jast90.web.common.controller.BaseController;
import io.github.jast90.web.common.result.CommonResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Created by jast90 on 2021/3/8
 */
@RestController
public class MyClassRestController extends BaseController<MyClassService, MyClass> {

    @PostMapping("my/class/page")
    @Override
    public CommonResult<Page<MyClass>> queryPage(@RequestBody CommonPageRequestBody<PageRequest, MyClass> requestBody) {
        return service.queryPage(requestBody.getPageRequest(),requestBody.getDomain());
    }

    @PostMapping("my/class/list")
    @Override
    public CommonResult<List<MyClass>> queryListByCondition(@RequestBody MyClass myClass) {
        return service.queryListByCondition(myClass);
    }

    @GetMapping("my/class/{id}")
    @Override
    public CommonResult<MyClass> queryById(@PathVariable("id") long id) {
        return service.queryById(id);
    }

    @PostMapping("my/class")
    @Override
    public CommonResult<MyClass> add(@RequestBody MyClass entity) {
        return service.add(entity);
    }

    @PutMapping("my/class")
    @Override
    public CommonResult<MyClass> update(@RequestBody MyClass entity) {
        return service.updateById(entity);
    }

    @DeleteMapping("my/class/{id}")
    @Override
    public CommonResult<MyClass> delete(@PathVariable("id") long id) {
        return service.deleteById(id);
    }
}
